<template>
  <view class="recharge" :style="{ height: wHeight + 'px' }">
    <view class="rechargeBox">
      <view style="height: 30rpx"></view>
      <view class="rechargeCard">
        <view class="recharge-num">
          <view>
            {{ userInfo.totalMoney }}
          </view>
          <text>账户余额（元）</text>
        </view>
        <view class="line"></view>
        <view class="recharge-bottom">
          <view
            class="item"
            @tap="switchPage('/pages/invite/invite-withdrawal')"
          >
            <image src="../../static/icons/recharge_record.png" mode=""></image>
            <text>提现记录</text>
          </view>

          <view class="item" @tap="switchPage('/pages/invite/invite-record')">
            <image
              src="../../static/icons/transaction_records.png"
              mode=""
            ></image>
            <text>推广记录</text>
          </view>
        </view>
      </view>
      <view class="title"> 提现金额 </view>
      <view class="money-list">
        <view
          class="list-item"
          :class="{ active: listIndex == index }"
          v-for="(item, index) in moneyList"
          :key="index"
          @click="clickList(index)"
        >
          <view :class="{ textActive: listIndex == index }">{{
            item.num
          }}</view>
        </view>
      </view>
      <view class="money-input">
        <input
          type="digit"
          v-model="number"
          @focus="inputFocus"
          placeholder="输入要提现的金额"
          placeholder-style="font-size: 36rpx;color: #999999;"
        />
        <view class="line"></view>
      </view>
      <view class="title"> 提现说明 </view>
      <view class="text-list" v-for="(item, index) in textlist" :key="index">
        <view class="circle"></view>
        <view class="test">{{ item.text }}</view>
      </view>
    </view>
    <view class="btn" @click="withDrawal"> 确认提现 </view>
  </view>
</template>

<script lang="ts">
import { withdrawal } from "@/api/invite";
import Vue from "vue";
import { mapState } from "vuex";

export default Vue.extend({
  computed: {
    ...mapState("user", ["userInfo"]),
  },
  data() {
    return {
      wHeight: 0,
      number: 0,
      listIndex: 0,
      moneyList: [
        {
          num: "20元",
          value: 20,
        },
        {
          num: "30元",
          value: 30,
        },
        {
          num: "40元",
          value: 40,
        },
        {
          num: "50元",
          value: 50,
        },
        {
          num: "100元",
          value: 100,
        },
        {
          num: "200元",
          value: 200,
        },
      ],
      textlist: [
        {
          text: "每日提现总金额不大于200",
        },
        {
          text: "单笔提现金额不大于200,不小于20元",
        },
        {
          text: "每日提现次数不大于10次",
        },
      ],
    };
  },
  methods: {
    inputCheck() {
      if (this.number < 20) {
        this.number = 20;
        uni.showToast({ title: "单笔提现金额不能小于20", icon: "error" });
      }
      if (this.number > 200) {
        this.number = 200;
        uni.showToast({ title: "单笔提现金额不大于200", icon: "error" });
        return false;
      }
      return true;
    },
    inputFocus() {
      this.listIndex = -1;
      this.number = 0;
    },
    withDrawal() {
      uni.showModal({
        title: "提现权限向微信申请中",
        content: "四月末即可开通提现功能",
        showCancel: false,
      });
      // if (this.inputCheck()) {
      //   let number = this.number;
      //   withdrawl(number).then((res) => {
      //     if (res == true) {
      //       uni.showToast({ title: "提现成功", icon: "success" });
      //     }
      //   });
      // }
    },
    clickList(index: number) {
      console.log(index);
      this.listIndex = index;
      this.number = this.moneyList[index].value;
    },
    switchPage(url: string) {
      uni.navigateTo({
        url,
      });
    },
    //获取窗口高度
    getHeight() {
      uni.getSystemInfo({
        success: (res) => {
          console.log(res);
          this.wHeight = res.windowHeight;
          console.log(this.wHeight);
        },
      });
    },
  },
  mounted() {
    this.getHeight();
  },
});
</script>

<style lang="scss" scoped>
.recharge {
  background: #ffffff;
}

.textActive {
  color: #3988f9 !important;
}

.active {
  color: #3988f9 !important;
  background: #e5f0ff !important;
  border: 1rpx solid #3988f9 !important;
}

.circle {
  width: 13rpx;
  height: 13rpx;
  background: #3988f9;
  border-radius: 50%;
  margin-right: 10rpx;
}

.line {
  width: 614rpx;
  height: 1rpx;
  background: #f4f5f9;
  margin: 0 auto;
}

.rechargeBox {
  width: 100%;
  height: 220rpx;
  background: url(../../static/icons/bg.png) no-repeat;
  background-size: 100% 100%;

  .rechargeCard {
    width: 686rpx;
    height: 308rpx;
    background: #ffffff;
    box-shadow: 0rpx 3rpx 26rpx 0rpx rgba(63, 63, 63, 0.15);
    border-radius: 13rpx;
    margin: 0rpx auto;

    .recharge-num {
      display: flex;
      flex-direction: column;
      text-align: center;
      padding-top: 30rpx;

      view:first-child {
        font-size: 84rpx;
        font-weight: bold;

        text {
          font-size: 56rpx;
          color: #000000;
        }
      }

      text {
        font-size: 25rpx;
        color: #9f9f9f;
        margin-bottom: 22rpx;
      }
    }

    .recharge-bottom {
      display: flex;
      height: 98rpx;
      margin-top: 35rpx;

      .item {
        display: flex;
        height: 28rpx;
        align-items: center;

        image {
          width: 31rpx;
          height: 28rpx;
        }

        text {
          font-size: 27rpx;
          color: #000000;
          margin-left: 8rpx;
        }
      }

      .item:nth-child(1) {
        margin-left: 111rpx;
      }

      .item:nth-child(2) {
        margin-left: 172rpx;
      }
    }
  }
}

.title {
  font-size: 31rpx;
  font-weight: bold;
  color: #000000;
  padding: 46rpx 0rpx 20rpx 35rpx;
}

.money-list {
  width: 686rpx;
  height: 316rpx;
  margin: 20rpx 33rpx;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;

  .list-item {
    width: 215rpx;
    height: 145rpx;
    background: #ffffff;
    border: 1rpx solid #ebecf1;
    box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(229, 231, 233, 0.3);
    border-radius: 13rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    view:first-child {
      font-size: 38rpx;
      font-weight: bold;
      color: #333333;
    }

    view:last-child {
      font-size: 24rpx;
      color: #666666;
      margin-top: 20rpx;
    }
  }
}

.money-input {
  width: 686rpx;
  height: 170rpx;
  background: #ffffff;
  box-shadow: 0rpx 3rpx 12rpx 0rpx rgba(63, 63, 63, 0.07);
  border-radius: 13rpx;
  margin: 0 auto;

  input {
    margin: 40rpx 0rpx 10rpx 40rpx;
    height: 120rpx;
    font-size: 71rpx;
    color: #333333;
  }
}

.text-list {
  display: flex;
  align-items: center;
  padding-left: 44rpx;

  view:last-child {
    font-size: 24rpx;
    color: #999999;
    margin-left: 6rpx;
    margin-top: 10rpx;
  }
}

.btn {
  width: 697rpx;
  height: 90rpx;
  background: linear-gradient(90deg, #02a8ff, #0186ff);
  border-radius: 45rpx;
  text-align: center;
  line-height: 90rpx;
  color: #ffffff;
  position: fixed;
  bottom: 30rpx;
  left: 31rpx;
}
</style>
